package com.room.controller.workman;

import com.room.pojo.*;
import com.room.service.WorkService;
import javafx.beans.binding.ObjectExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @创建人 lin
 * @创建时间 2019/10/13
 * @描述
 */
@RestController
@RequestMapping("/work/basic")
public class WorkManController {

    @Autowired
    public WorkService workService;

    /**
     * 获得学生的分页数据
     * @param page
     * @param size
     * @return返回学生的分页数据
     */
    @RequestMapping(value = "/workman",method = RequestMethod.GET)
    public Map<String,Object> getWorkByPage(
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "6")Integer size
    ){

        Map<String,Object> map = new HashMap<String,Object>();
        List<Workman> students = workService.getWorkByPage(page,size);
        long total = workService.getTotal();
        map.put("stus",students);
        map.put("total",total);
        return map;
    }

    /**
     * 删除指定id的学生
     * @param ids
     * @return
     */
    @RequestMapping(value = "/work/{ids}",method = RequestMethod.DELETE)
    public DormResult deleteById(@PathVariable String ids){
        if(workService.deleteWorkById(ids)){
            return DormResult.ok("删除成功");
        }
        return DormResult.error("删除失败");
    }

    /**
     * 修改技工信息
     * @param teachaer
     * @return
     */
    @RequestMapping(value = "/work",method = RequestMethod.PUT)
    public DormResult updateStudent(Workman workman){
        if(workService.updateWorkman(workman)==1){
            return DormResult.ok("修改成功");
        }
        else{
            return DormResult.error("修改失败");
        }
    }

    /**
     * 根据工号获取学生数据
     * @param workNo
     * @return
     */
    @RequestMapping(value = "/workno",method = RequestMethod.GET)
    public Map<String, Object> getWorkmanByNo(@RequestParam String workNo){
        Map<String,Object> map = new HashMap<String,Object>();
        if(workNo==null){
            map.put("workByNo","");
        }
        else {
           Workman workman = workService.getWorkmanByNo(workNo);
           map.put("workByNo",workman);
        }
        return map;
    }

//    /**
//     * 添加技工数据
//     * @param repairitmes
//     * @return
//     */
//    @RequestMapping(value = "/work",method = RequestMethod.POST)
//    public DormResult addwork( Workman workman) {
//        repairitmes.setReptime(new Date());
//        int flag = repairService.addRepairitems(repairitmes);
//        if(flag==1){
//            return DormResult.ok("报修成功");
//        }
//        return DormResult.ok("报修失败");
//    }
}
